package com.example.administrator.yuejian2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.bean.QuestionBean;
import com.example.administrator.yuejian2.viewholder.QuestionViewHolder;

import java.util.List;

public class QuestionAdapter extends RecyclerView.Adapter{
    private Context context;
    private LayoutInflater layoutInflater;
    private List<QuestionBean> list;
    public QuestionAdapter(Context context)
    {
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }

    public  void getQuestionList(List<QuestionBean> list)
    {
        this.list=list;
        notifyDataSetChanged();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.question_item,parent,false);
        return new QuestionViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        QuestionViewHolder questionViewHolder=(QuestionViewHolder)holder;
        final QuestionBean bean=list.get(position);
        questionViewHolder.user_question_list_title.setText(bean.getQuestion_content());
        questionViewHolder.user_question_list_author.setText(bean.getQuestion_time());
    }

    @Override
    public int getItemCount() {
        if (list==null)
        {
            return 0;
        }
        else
        {
            return  list.size();
        }
    }
}
